<%@page import="java.sql.DriverManager"%>
<%@page import="java.sql.ResultSet"%>
<%@page import="java.sql.PreparedStatement"%>
<%@page import="java.sql.Connection"%>
<%@page contentType="text/html; charset=utf-8" 
pageEncoding="utf-8" %>
<%
	String DRV = "org.mariadb.jdbc.Driver";
	String URL = "jdbc:mariadb://localhost:3306/untiring07?user=untiring07&password=123456";
	String SQL = "select * from boardv4 where bdno = ?";
	Connection conn = null;
	PreparedStatement pstmt = null;
	ResultSet rs = null;
%>
<%
	String bdno = null;
	String title = null;
	String uid = null;
	String contents = null;
%>
<%
	bdno = request.getParameter("bdno");
	// 조회할 본문글 번호가 입력되지 않으면
	// 자동으로 list.jsp로 이동시킴
	if (bdno==null) response.sendRedirect("list.jsp");
%>
<%
	try {
		Class.forName(DRV);
		conn = DriverManager.getConnection(URL);

		pstmt = conn.prepareStatement(SQL);
			pstmt.setString(1, bdno);
		rs = pstmt.executeQuery();
		
		if (rs.next()) {
			title = rs.getString("title");
			uid = rs.getString("uid");
			contents = rs.getString("contents");
			// <br /> 를 \r\n 으로 변경
			contents = contents.replace( "<br />", "\r\n" );
		}else {
			// 입력한 본문글 번호가 boardv4에 
			// 존재하지 않으면 자동으로 list.jsp로 이동시킴
			response.sendRedirect("list.jsp");
		}
	} catch (Exception ex) {
		ex.printStackTrace();
	} finally {
		if (rs != null) try { rs.close(); } catch (Exception e) {}
		if (pstmt != null) try { pstmt.close(); } catch (Exception e) {}
		if (conn != null) try { conn.close(); } catch (Exception e) {}
	}
%>

<!DOCTYPE html>
<html lang="ko">
	<head>
		<meta charset="utf-8">
		<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
		<title>JSP 프로젝트 v1</title>
		<link type="text/css" href="../css/layout.css"
			rel="stylesheet" />
		<style type="text/css">
			
		</style>
	</head>

	<body>
		<div>
			<h1>JSP 프로젝트 v1</h1><!-- 제목 -->
			<ul id="nav">
				<li><a href="../index.html">Home</a></li>
				<li><a href="../member/join.html">회원가입</a></li>
				<li><a href="../member/login.html">로그인</a></li>
				<li><a href="list.html">게시판</a></li>
				<li><a href="../member/myinfo.html">회원정보</a></li>
			</ul>	<!-- 상단메뉴 -->
			<hr />
		</div><!-- // header -->
		<div id="content">
			<h2>게시판 수정하기</h2>
			<form action="updateok.jsp" 
				method="post" 	name="board">
				<div>제목 <input type="text" name="title" value="<%=title %>" /></div>
				<div>작성자 <input type="text" name="uid" value="<%=uid%>"/></div>
				<div>본문 <textarea name="contents" 
						cols="60" rows="15"><%=contents %></textarea></div>
				<div><button type="submit">수정완료</button></div>
				<input type="hidden" name="bdno" 
				value="<%=bdno %>" />
			</form>
		</div><!-- // content -->
		<div>
			<hr />
			<p id="copy">copyrights(c) 2013. siestageek. 
				all rights reserved.</p>
		</div><!-- // footer -->
	</body>
</html>




